**** Replication for Accominotti/Albers/Oosterlinck: "Selective default risk"

* Software required: The software for this research paper was written with Stata 17 and Matlab 2022;
* The replication can be executed in Stata entirely - Matlab will be called, opened, exectuted, and closed once not commented out.
* If you have a matlab license, just run the code lines "shell  "$MATLABPATH" "". The script will then reproduce the yield-to-maturity estimates generated by Matlab but instead employ those that we left in the directory for this purpose; you may have to open the matlab script to adjust the rootfolder * 



**** Prelims
	clear
	* set cd 
	
	
	
	* insert Matlab path here (if you want to reproduce yield to maturity estimates)
	global MATLABPATH "/Applications/MATLAB_R2023a.app/bin/matlab"
	
	
	* insert the path where you unzipped the replication folder (it is preset on the dropbox folder on a Mac)
	global Replicationdirectory "~/Dropbox/Data and Replication/Selective default risk/AAO_Selective Default Risk"
		
	 
	* define cd
	cd "$Replicationdirectory"

	
	* Define global for 4 markets
	
	global markets `" "london" "paris" "amsterdam" "zurich" "'
	
	

	* Define plot style 
		grstyle init
		grstyle set plain, horizontal grid dotted


	
	
**** DATA PREP

			

 	
	
	 
					
				* Prepare bond data (this generates the dataset of bond prices, trading days, ytms etc)  
	
						* DAWES
							* load data and make currency conversions etc
							do "$Replicationdirectory/_Work/Scripts/1_1_DATA_PREP_DAWESBONDS"
					 						
						
						* Consol
							* load consol data 
							do "_Work/Scripts/1_2_DATA_PREP_CONSOL"
				
											 
							
				
				* Generate Panel dataset
				
				
						do "$Replicationdirectory/_Work/Scripts/1_3_DATA_PREP_GEN_PANEL.do"
			
				
				
				* Prepare Roll's liquidity measure  and add to panel 
		
						do "$Replicationdirectory/_Work/Scripts/1_4_DATA_PREP_Liquidity_ROLL.do"
						 
					
					 
				* Generate events data set 
		
 
						do "$Replicationdirectory/_Work/Scripts/1_5_DATA_PREP_GenerateEVENTS_ytm.do"

						
						
						   
				* Matlab scripts for calculating yields-to-maturity. Uncomment if you want to reproduce ytm estimates (otherwise they are simply loaded from the data folder)
				
					
							* calculate ytm in Matlab (this is necessary for the first run), then rerun  "1_1_DATA_PREP_DAWESBONDS"
								*shell  "$MATLABPATH"  -noFigureWindows -r "try; run('$Replicationdirectory/_Work/Scripts/M_1_2_Calculate_YTM_Matlab.m'); catch; end; quit"
						 
							* calculate ytm in Matlab
								*shell  "$MATLABPATH"  -noFigureWindows -r "try; run('$Replicationdirectory/_Work/Scripts/M_1_2b_Calculate_OTHERRISKYBONDS_YTM_Matlab.m'); catch; end; quit"
							
							* export Table  for Appendices (this requires Matlab )
								*shell  "$MATLABPATH"  -noFigureWindows -r "try; run('$Replicationdirectory/_Work/Scripts/M_5_1_NEWSPAPER_DOC.m'); catch; end; quit"
				
				
*****  Section 2
		
		
		* Figures that show yields and prices (Figure 1 )
			do "$Replicationdirectory/_Work/Scripts/2_1_Descriptive_Figures"
			
			
			
***** Section 3 

		* Arbitrage (Section 3.2)
		
			*  (1) Arbitrage Local Projections (based on Jorda 2005's stata program)
		
		
					* 1a) Dawes
						do "$Replicationdirectory/_Work/Scripts/3_2a_Arbitrage_Dawes"
				
					* 1b) Consol 
						do "$Replicationdirectory/_Work/Scripts/3_2b_Arbitrage_dailyConsols"
						
					* 1c) Combine graphs 
						do "$Replicationdirectory/_Work/Scripts/3_2c_Arbitrage_CombinedFigure"
		
		
			* (2) Arbitrage (Volumes)
					
					do "$Replicationdirectory/_Work/Scripts/3_2d_Arbitrage_Quantities"
					
					
					
						 
		
		* (3) Liqudity elasticity 
		 
							* Summary statistics 
							do "$Replicationdirectory/_Work/Scripts/3_3a_Liquidity_BID_ASK"

							* Liquidity elasticity 
							do "$Replicationdirectory/_Work/Scripts/3_3b_Liquidity_BID_ASK_elasticity"

		

		* (4) Decomposition
		 
				
				do "$Replicationdirectory/_Work/Scripts/3_4_Decomposition"
	

	
	
****** Section 4


	
		* (1) Descriptive Graphs on trade (based on trade data)

			do "$Replicationdirectory/_Work/Scripts/4_1_SeniorityRanking_Trade_Figures.do"
		
				
		* (2) News regressions 
	
 				 
 			do "$Replicationdirectory/_Work/Scripts/4_2_Seniority_NEWS_Regressions"
		
		
 		
		
		
 		
		
**** Appendix Material 

		* Figures with additional appendix material
			do "$Replicationdirectory/_Work/Scripts/5_1_Descriptive_Figures_Appendix"
		
				
				
		* Regression with the effect of general news on any or general default risk 
			do "$Replicationdirectory/_Work/Scripts/5_2_RegressionAnyDefaultAppendix"
				
	
	
	
	
	
	
